home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / security / ProtectionDomain.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  3.0 KB  |  105 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)ProtectionDomain.java    1.24 98/05/11
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.security;
  16.  
  17. /** 
  18.  *
  19.  * <p> This ProtectionDomain class encapulates the characteristics of
  20.  * a domain, which encloses a set of classes whose instances
  21.  * are granted the same set of permissions.
  22.  * 
  23.  * <p>In addition to a set of permissions, a domain is comprised of a 
  24.  * CodeSource, which is a set of PublicKeys together with a codebase (in 
  25.  * the form of a URL). Thus, classes signed by the same keys and
  26.  * from the same URL are placed in the same domain.
  27.  * Classes that have the same permissions but are from different code
  28.  * sources belong to different domains.
  29.  *
  30.  * <p> A class belongs to one and only one ProtectionDomain.
  31.  * 
  32.  * @version     1.24, 05/11/98
  33.  * @author Li Gong 
  34.  * @author Roland Schemers
  35.  */
  36.  
  37. public class ProtectionDomain {
  38.  
  39.     /* CodeSource */
  40.     private CodeSource codesource ;
  41.  
  42.     /* the rights this protection domain is granted */
  43.     private PermissionCollection permissions;
  44.  
  45.     /**
  46.      * Creates a new ProtectionDomain with the given CodeSource and
  47.      * Permissions. If the permissions object is not null, then
  48.      * <code>setReadOnly()</code> will be called on the passed in 
  49.      * Permissions object.
  50.      *
  51.      * @param codesource the codesource associated with this domain
  52.      * @param permissions the permissions granted to this domain
  53.      */
  54.     public ProtectionDomain(CodeSource codesource,
  55.                 PermissionCollection permissions) {
  56.     this.codesource = codesource;
  57.     if (permissions != null) {
  58.         this.permissions = permissions;
  59.         this.permissions.setReadOnly();
  60.     }
  61.     }
  62.  
  63.     /**
  64.      * Returns the CodeSource of this domain.
  65.      * @return the CodeSource of this domain.
  66.      */
  67.     public final CodeSource getCodeSource() {
  68.     return this.codesource;
  69.     }
  70.  
  71.  
  72.     /** 
  73.      * Returns the permissions of this domain.
  74.      * @return the permissions of this domain.
  75.      */
  76.     public final PermissionCollection getPermissions() {
  77.     return this.permissions;
  78.     }
  79.  
  80.     /**
  81.      * Check and see if this ProtectionDomain implies the permissions 
  82.      * expressed in the Permission object.
  83.      *
  84.      * @param permission the Permission object to check.
  85.      *
  86.      * @return true if "permission" is a proper subset of a permission in 
  87.      * this ProtectionDomain, false if not.
  88.      */
  89.  
  90.     public boolean implies(Permission permission) {
  91.     if (permissions != null) {
  92.         return permissions.implies(permission);
  93.     } else {
  94.         return false;
  95.     }
  96.     }
  97.  
  98.     /**
  99.      * Convert a ProtectionDomain to a String.
  100.      */
  101.     public String toString() {
  102.     return "ProtectionDomain "+codesource+"\n"+permissions+"\n";
  103.     }
  104. }
  105.